package com.codeduck.kafka.demo.consumer;

import com.codeduck.kafka.demo.message.MessageDemo01;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.common.header.Headers;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 *
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2022-01-08
 */
@Component
@Slf4j
public class ConsumerDemo01 {

    // 一般情况下，建议一个消费者分组，仅消费一个 Topic 。这样做会有个好处：每个消费者分组职责单一，只消费一个 Topic 。
    @KafkaListener(topics = MessageDemo01.TOPIC, groupId = "consumer-group-a-" + MessageDemo01.TOPIC)
    public void onMessage(MessageDemo01 record) {
        log.info("[onMessage][线程编号:{} 消息内容：{}]", Thread.currentThread().getId(), record);
    }
}
